import httpx
from configuration import Config

class MCPClient:
    def __init__(self, config: Config):
        self.config = config
        self.base_url = config.mcp_server['base_url']
        
    async def generate_commit(self, repo_path: str, auto_generate: bool = True, commit_message: str = None):
        """
        调用服务器生成提交信息
        """
        async with httpx.AsyncClient() as client:
            response = await client.post(
                f"{self.base_url}/api/commit",
                json={
                    "repo_path": repo_path,
                    "commit_message": commit_message,
                    "auto_generate": auto_generate
                }
            )
            response.raise_for_status()
            return response.json()
            
    async def analyze_repo(self, repo_path: str):
        """
        调用服务器分析仓库
        """
        async with httpx.AsyncClient() as client:
            response = await client.get(f"{self.base_url}/api/analyze/{repo_path}")
            response.raise_for_status()
            return response.json()